﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject;
using NoMvvm.Ninject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;

namespace NoMvvm.UnitTests
{
    namespace Ninject
    {
        #region Test Types

        public sealed class TestView
        {

        }

        sealed class TestViewModel : ViewModel
        {

        }

        interface ITestInterface
        {
            void Test();
        }

        sealed class TestClassA : ITestInterface
        {
            public void Test()
            {
                throw new NotImplementedException();
            }
        }

        sealed class TestClassB : ITestInterface
        {
            public void Test()
            {
                throw new NotImplementedException();
            }
        }

        sealed class TestClassC : ITestInterface
        {
            public void Test()
            {
                throw new NotImplementedException();
            }
        }

        sealed class TestClassD : ITestInterface
        {
            public void Test()
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }

    [TestClass]
    public class NinjectTest
    {
        private readonly Assembly _assembly = Assembly.GetExecutingAssembly();

        [TestMethod]
        public void Get_View()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);
            var view = container.GetView("Test");

            Assert.IsInstanceOfType(view, typeof(Ninject.TestView));
        }

        [TestMethod]
        public void Get_ViewModel()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);
            var viewModel = container.GetViewModel("Test");

            Assert.IsInstanceOfType(viewModel, typeof(Ninject.TestViewModel));
        }

        [TestMethod]
        public void Get_ViewFor()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);

            var viewModel = container.GetViewModel("Test");
            var view = container.GetViewFor(viewModel);

            Assert.IsInstanceOfType(view, typeof(Ninject.TestView));
        }

        [TestMethod]
        public void Get_Many()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);

            foreach (var item in container.GetMany<Ninject.ITestInterface>())
            {
                Assert.IsNotNull(item);
            }
        }

        [TestMethod]
        public void Get_Many_Dynamic()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);

            foreach (var item in container.GetMany("Testing123"))
            {
                Assert.IsInstanceOfType(item, typeof(Ninject.ITestInterface));
            }
        }

        [TestMethod]
        public void Get()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);
            kernel.Bind<Ninject.ITestInterface>().To<Ninject.TestClassA>();
            var item = container.Get<Ninject.ITestInterface>();

            Assert.IsInstanceOfType(item, typeof(Ninject.TestClassA));
        }

        [TestMethod]
        public void Get_Dynamic()
        {
            var kernel = new StandardKernel();
            var container = new Adapter(kernel, _assembly);
            kernel.Bind<object>().To<Ninject.TestClassC>().Named("Testing123");
            var item = container.Get("Testing123");

            Assert.IsInstanceOfType(item, typeof(Ninject.TestClassC));
        }
    }
}
